package org.bugjail.servlet.form.edit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.TestDesign;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.servlet.BasicUIServlet;

public class EditTestDesignFormServlet extends BasicUIServlet {

	static final long serialVersionUID = 1L;

	private TestDesign testDesign;
	
	@Override
	protected void write(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		//int projectid = Integer.parseInt(request.getParameter("projectid"));
		
		PrintWriter pw = response.getWriter();

		pw.println("<form method='post' action='EditTestDesignServlet'>");
		pw.println("Test design name:<br><input type='text' name='name' maxlength='50' value='"+testDesign.getName()+"' /><br>");
		pw.println("Test design description:<br><textarea name='description'>"+testDesign.getDescription()+"</textarea><br>");
		pw.println("<input type=hidden name='testdesignid' value='"+testDesign.getId()+"' />");
		pw.println("<input type=submit value='Update' />");
		pw.println("&nbsp;<a href='TestDesignServlet?project="+testDesign.getProject().getId()+"'>Cancel</a>");
		pw.println("</form>");
	}

	@Override
	protected String pageTitle() {
		return "Edit test design";
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int testdesignid = Integer.parseInt(request.getParameter("testdesignid"));
		testDesign = DAOFactory.getDAOFactory().getTestDesignDAO().retrieveById(testdesignid);
	}
}